# -*- coding:utf-8 -*-
import json
import os
import platform
from common.store import DB


# 创建用例的存储目录
class CreateDir:
    def __init__(self):
        if platform.system().lower() == 'windows':
            self.windows()
        elif platform.system().lower() == 'linux':
            self.linux()
        elif platform.system().lower() == 'darwin':
            self.darwin()

    def windows(self):
        # 创建静态文件夹
        file_dir = os.listdir()
        if DB.DirName not in file_dir:
            os.mkdir(DB.DirName)
            try:
                import win32con, win32api
                try:
                    win32api.SetFileAttributes(DB.DirName, win32con.FILE_ATTRIBUTE_HIDDEN)
                except Exception:
                    pass
            except ModuleNotFoundError:
                pass

    def linux(self):
        file_dir = os.listdir()
        if DB.DirName not in file_dir:
            # 创建静态文件夹
            os.mkdir(DB.DirName)

    def darwin(self):
        file_dir = os.listdir()
        if DB.DirName not in file_dir:
            # 创建静态文件夹
            os.mkdir(DB.DirName)


def create_case_dir():
    CreateDir()

    if not os.path.exists(os.path.join(DB.ABSPATH, DB.DirName, DB.case_task_name)):
        os.mkdir(os.path.join(DB.ABSPATH, DB.DirName, DB.case_task_name))
